Repository navigation
Fix in-memory cache namespace invalidation boundaries - #578
Open
anishpentyala wants to merge 5 commits into
Open
anishpentyala wants to merge 5 commits into
anishpentyala wants to merge 5 commits into
Conversation
Fixes an issue with in-memory namespace invalidation that incorrectly deleted sibling namespaces or application prefixes sharing the same initial text. Updates namespace matching to require a colon separator, aligning with Redis backend behavior.
This was referenced Nov 13, 2026
agustin18
added a commit
to agustin18/fastapi-cache
that referenced
this pull request
Nov 14, 2026
…aries (#7) * fix(clear): delete only the requested key and enforce namespace boundaries Fix FastAPICache.clear(key=...) so it deletes only that key (long2ice#451/long2ice#529). Require the ':' boundary for InMemory and Redis namespace clears (long2ice#578). Replace Redis KEYS/Lua with SCAN/UNLINK; Redis Cluster namespace clear raises NotImplementedError. Add InMemory and Redis 7 integration tests, Redis Cluster unit tests, and migration notes. * ci: run Redis integration tests in the main matrix Install the redis extra and start a Redis 7 service so changed-line coverage includes the Redis clear code.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
InMemoryBackend.clear(namespace=...)matches the namespace as an arbitrary string prefix. With the default key builder, clearingapp:useralso removes cached entries inapp:usersandapp:username. Clearing the entireappprefix can similarly remove entries belonging toapplicationin the shared in-memory store.Change
Require the colon separator after the namespace, matching the existing Redis backend convention. Nested namespaces are still included. Add direct backend boundary tests, decorated-function tests for
FastAPICache.clear, and controls for key-only clearing and no-argument behavior. Include an unnumbered towncrier fragment, verified with the project's towncrier 22.12.0 draft builder.Compatibility note: a raw custom key exactly equal to the namespace, with no following colon, is now retained. Such a key is also not matched by Redis's existing
namespace:*behavior. Custom key-builder formats, Redis glob-metacharacter behavior, expiry, and key-vs-namespace argument precedence are not changed. This is separate from #529 and #571.Verification
Actual Python 3.8.20, 3.10.12, 3.11.17, and 3.13.17:
git diff --checkpasses.No external backend service, mypy, or pyright run is claimed.